package tools;

import java.sql.*;

public class DataTools 
{
	
	public static Connection getConnection()
	{
		
		Connection connection = null;
		try 
		{
			// Load the JDBC driver
			String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
			Class.forName(driverName);

			// Create a connection to the database
			String serverName = "127.0.0.1:3306";
			String mydatabase = "geo_experiments";
			String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
			String username = "crawler";
			String password = "crawler";
			connection = DriverManager.getConnection(url, username, password); 			
			
		} catch (ClassNotFoundException e) 
		{
			System.out.println("Database not found");
		}
		catch (SQLException e) {
			System.out.println("Connection failed");
		}
		return connection;		
	}
	
	public static int CreatePlatform(String platformName, String publisher)
	{	
		
		int platformID = 0;
	    CallableStatement cs;
		try 
		{	
			Connection conn = getConnection();
			String proc = "{ call input_createplatform(?, ?, ?) }";
			cs = conn.prepareCall(proc);			    
	    
		    cs.setString(1,platformName); 
		    cs.setString(2,publisher);
		    cs.setInt(3, platformID);
		    
		    cs.execute();
		    
		    System.out.println("Success");
		    conn.close();		    
	    
		} catch (SQLException e) {
			
			System.out.println("Query failed");			
		}	
		
		return platformID;
	    
	}
	
}